<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Solr控制脚本参考 - (power up)</title>
  <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="Kevin Jiang" /><meta name="description" content="Solr包含了一个命令行工具bin/solr可以用来执行非常多的常用操作。可以启动、停止Solr，创建删除collection/core，对" /><meta name="keywords" content="KevinJiang, AI大模型, AI落地, 全栈工程师, Java, Spring Boot" />






<meta name="generator" content="Hugo 0.84.4 with theme even" />


<link rel="canonical" href="http://kevinjiang.info/post/searchengine/solr%E6%8E%A7%E5%88%B6%E8%84%9A%E6%9C%AC%E5%8F%82%E8%80%83/" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">



<link href="/sass/main.min.78f8f17bab244b9ee62ad16480c9584d5fc2db06ae20681d1ca225cefd80767c.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">


<meta property="og:title" content="Solr控制脚本参考" />
<meta property="og:description" content="Solr包含了一个命令行工具bin/solr可以用来执行非常多的常用操作。可以启动、停止Solr，创建删除collection/core，对" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://kevinjiang.info/post/searchengine/solr%E6%8E%A7%E5%88%B6%E8%84%9A%E6%9C%AC%E5%8F%82%E8%80%83/" /><meta property="article:section" content="post" />
<meta property="article:published_time" content="2018-03-19T15:52:38+00:00" />
<meta property="article:modified_time" content="2018-03-19T15:52:38+00:00" />

<meta itemprop="name" content="Solr控制脚本参考">
<meta itemprop="description" content="Solr包含了一个命令行工具bin/solr可以用来执行非常多的常用操作。可以启动、停止Solr，创建删除collection/core，对"><meta itemprop="datePublished" content="2018-03-19T15:52:38+00:00" />
<meta itemprop="dateModified" content="2018-03-19T15:52:38+00:00" />
<meta itemprop="wordCount" content="3860">
<meta itemprop="keywords" content="Solr," /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Solr控制脚本参考"/>
<meta name="twitter:description" content="Solr包含了一个命令行工具bin/solr可以用来执行非常多的常用操作。可以启动、停止Solr，创建删除collection/core，对"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->

</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/" class="logo">(Power up)</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="/">
        <li class="mobile-menu-item">首页</li>
      </a><a href="/post/">
        <li class="mobile-menu-item">归档</li>
      </a><a href="/tags/">
        <li class="mobile-menu-item">标签</li>
      </a><a href="/categories/">
        <li class="mobile-menu-item">分类</li>
      </a><a href="/resume/">
        <li class="mobile-menu-item">简历</li>
      </a>
  </ul>

  


</nav>

  <div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/" class="logo">(Power up)</a>
</div>





<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
        <a class="menu-item-link" href="/">首页</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/post/">归档</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/tags/">标签</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/categories/">分类</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/resume/">简历</a>
      </li>
  </ul>
</nav>

    </header>

    <main id="main" class="main">
      <div class="content-wrapper">
        <div id="content" class="content">
          <article class="post">
    
    <header class="post-header">
      <h1 class="post-title">Solr控制脚本参考</h1>

      <div class="post-meta">
        <span class="post-time"> 2018-03-19 </span>
        
          <span class="more-meta"> 约 3860 字 </span>
          <span class="more-meta"> 预计阅读 8 分钟 </span>
        
      </div>
    </header>

    <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content always-active">
    <nav id="TableOfContents">
  <ul>
    <li><a href="#启动与重启">启动与重启</a></li>
    <li><a href="#启动参数">启动参数</a>
      <ul>
        <li><a href="#-a-string"><code>-a &quot;&lt;string&gt;&quot;</code></a></li>
        <li><a href="#-cloud"><code>-cloud</code></a></li>
        <li><a href="#-d-dir"><code>-d &lt;dir&gt;</code></a></li>
        <li><a href="#-e-name"><code>-e &lt;name&gt;</code></a></li>
        <li><a href="#-f"><code>-f</code></a></li>
        <li><a href="#-h-hostname"><code>-h &lt;hostname&gt;</code></a></li>
        <li><a href="#-m-memory"><code>-m &lt;memory&gt;</code></a></li>
        <li><a href="#-noprompt"><code>-noprompt</code></a></li>
        <li><a href="#-p-port"><code>-p &lt;port&gt;</code></a></li>
        <li><a href="#-s-dir"><code>-s &lt;dir&gt;</code></a></li>
        <li><a href="#-v"><code>-v</code></a></li>
        <li><a href="#-q"><code>-q</code></a></li>
        <li><a href="#-v-1"><code>-V</code></a></li>
        <li><a href="#-z-zkhost"><code>-z &lt;zkHost&gt;</code></a></li>
        <li><a href="#-force"><code>-force</code></a></li>
      </ul>
    </li>
    <li><a href="#设置jvm参数">设置JVM参数</a></li>
  </ul>

  <ul>
    <li><a href="#停止参数">停止参数</a>
      <ul>
        <li><a href="#-p-port-1"><code>-p &lt;port&gt;</code></a></li>
        <li><a href="#-all"><code>-all</code></a></li>
        <li><a href="#-k-key"><code>-k &lt;key&gt;</code></a></li>
      </ul>
    </li>
  </ul>

  <ul>
    <li><a href="#版本">版本</a></li>
    <li><a href="#状态">状态</a></li>
    <li><a href="#assert-检查安装正确">Assert 检查安装正确</a></li>
    <li><a href="#健康检查">健康检查</a>
      <ul>
        <li><a href="#选项参数">选项参数</a></li>
      </ul>
    </li>
  </ul>

  <ul>
    <li><a href="#创建数据集合">创建数据集合</a>
      <ul>
        <li><a href="#创建数据集合的选项参数">创建数据集合的选项参数</a></li>
      </ul>
    </li>
  </ul>
</nav>
  </div>
</div>
    <div class="post-content">
      <p>Solr包含了一个命令行工具<code>bin/solr</code>可以用来执行非常多的常用操作。可以启动、停止Solr，创建删除collection/core，对ZooKeeper的操作，以及检查solr状态和配置分片。</p>
<p><code>bin/solr</code>的使用格式如下：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bin/solr cmd [options]
</code></pre></td></tr></table>
</div>
</div><!-- raw HTML omitted -->
<h1 id="启动-start">启动 Start</h1>
<h2 id="启动与重启">启动与重启</h2>
<p><code>start</code>命令用来启动solr。<code>restart</code>可以用来重启solr，不管是从停止状态还是在运行状态。</p>
<p><code>start</code>和<code>restart</code>有很多的选项，可以指定运行在SolrCloud模式，可以使用自带的样例配置集，同时还可以指定hostname, port, ZooKeeper。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bin/solr start [options]
bin/solr start -help
bin/solr restart [options]
bin/solr restart -help
</code></pre></td></tr></table>
</div>
</div><p>当使用<code>restart</code>命令时，命令参数必须与<code>start</code>的命令参数一致。重启的过程是先执行<code>stop</code>命令停止solr，然后再启动solr，所以<code>restart</code>的参数必须要跟<code>start</code>的参数一致。</p>
<h2 id="启动参数">启动参数</h2>
<p><code>bin/solr</code>命令行脚本提供了非常多的选项来定制solr服务，例如改变监听的端口。其实默认的参数已经能够满足很多情况的需求了。</p>
<h3 id="-a-string"><code>-a &quot;&lt;string&gt;&quot;</code></h3>
<p>指定JVM参数，例如<code>-X</code>。如果是以<code>-D</code>传递的JVM参数，-a选项可以忽略。</p>
<p><strong>Example</strong>：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bin/solr start -a &#34;-Xdebug -Xrunjdwp:transport=dt_socket, server=y,suspend=n,address=1044&#34;
</code></pre></td></tr></table>
</div>
</div><h3 id="-cloud"><code>-cloud</code></h3>
<p>在SolrCloud模式启动，同时启动内置的ZooKeeper。这个选项可以简写为：<code>-c</code>。如果已经有一个ZooKeeper实例在运行，可以使用<code>-z</code>选项参数替换内置的ZooKeeper。查看更多<a href="http://lucene.apache.org/solr/guide/7_2/solr-control-script-reference.html#solrcloud-mode">SolrCloud</a>细节。</p>
<p><strong>Example</strong>：<code>bin/solr start -c</code></p>
<h3 id="-d-dir"><code>-d &lt;dir&gt;</code></h3>
<p>定义server目录，默认为<code>server</code>。server目录的作用是提供web服务，rest api。这个选项一般不需要覆盖。当在同一台机器启动多个solr实例时，更常用的办法是使用<code>-s</code>选项来指定不同的solr.home，以存放不同的配置和数据。</p>
<p><strong>Example</strong>：<code>bin/solr start -d newServerDir</code></p>
<h3 id="-e-name"><code>-e &lt;name&gt;</code></h3>
<p>以样例配置启动solr。solr提供的这些样例配置以帮助你快速开始熟悉solr的使用，或者某些特性。</p>
<p>这些样例包括：</p>
<ul>
<li>cloud</li>
<li>techproducts</li>
<li>dih</li>
<li>schemaless</li>
</ul>
<p>点击<a href="http://lucene.apache.org/solr/guide/7_2/solr-control-script-reference.html#running-with-example-configurations">Running with Example Configurations</a>查看详情。</p>
<p><strong>Example</strong>：<code>bin/solr start -e schemaless</code></p>
<h3 id="-f"><code>-f</code></h3>
<p>在前台运行。使用<code>-e</code>选项的时候此选项不能使用。</p>
<p><strong>Example</strong>：<code>bin/solr start -f</code></p>
<h3 id="-h-hostname"><code>-h &lt;hostname&gt;</code></h3>
<p>指定hostname，如果此选项没有指定，默认使用localhost。</p>
<p><strong>Example</strong>：<code>bin/solr start -h kevinjiang.info</code></p>
<h3 id="-m-memory"><code>-m &lt;memory&gt;</code></h3>
<p>指定启动时JVM最小（-Xms）、最大（-Xmx）堆内存。</p>
<p><strong>Example</strong>：<code>bin/solr start -m 1g</code></p>
<h3 id="-noprompt"><code>-noprompt</code></h3>
<p>些选项会隐藏所有的提示信息，所有的配置都使用默认值。例如，当使用cloud样例时，会出现一个交互session，以步骤的方式来选择或输入一些配置来启动SolrCloud集群，可以使用-noprompt接受默认值。</p>
<p><strong>Example</strong>：<code>bin/solr start -e cloud -noprompt</code></p>
<h3 id="-p-port"><code>-p &lt;port&gt;</code></h3>
<p>指定端口，默认是8983端口，如果没有使用-z选项指定ZooKeeper，ZooKeeper端口默认+1000，为：9983</p>
<p><strong>Example</strong>：<code>bin/solr start -p 8655</code></p>
<h3 id="-s-dir"><code>-s &lt;dir&gt;</code></h3>
<p>指定<code>solr.solr.home</code>参数，Solr的数据与配置将会写到这个目录下面。通过这个选项可以启动多个实例，同时可以使用<code>-d</code>选项指定相同的server目录。</p>
<p>如果指定此选项，相应的目录需要包含一个名为<code>solr.xml</code>的文件，除非<code>solr.xml</code>已经存在于ZooKeeper。默认值为：<code>server/solr</code></p>
<p>如果使用<code>-e</code>选项，此选项将被忽略，<code>solr.solr.home</code>会根据不同的样例而不同。</p>
<p><strong>Example</strong>：<code>bin/solr start -s newHome</code></p>
<h3 id="-v"><code>-v</code></h3>
<p>指定输出更多的日志信息，日志级别会从<code>INFO</code>修改为<code>DEBUG</code>，如果修改<code>log4j.properties</code>，也可以达到同样的效果。</p>
<p><strong>Example</strong>：<code>bin/solr start -f -v</code></p>
<h3 id="-q"><code>-q</code></h3>
<p>指定输出更少的日志信息，日志级别会从<code>INFO</code>修改为<code>WARN</code>，如果修改<code>log4j.properties</code>，也可以达到同样的效果。这在生产环境是比较实用的，可以指定只记录warning和error级别的日志。</p>
<p><strong>Example</strong>：<code>bin/solr start -f -q</code></p>
<h3 id="-v-1"><code>-V</code></h3>
<p>启动此选项将会在命令行输出更为详细的信息</p>
<p><strong>Example</strong>：<code>bin/solr start -V</code></p>
<h3 id="-z-zkhost"><code>-z &lt;zkHost&gt;</code></h3>
<p>指定ZooKeeper连接字符串，些选项仅与<code>-c</code>选项同时使用来启动SolrCloud模式。如果些选项没有指定，在SolrCloud模式下，Solr会启动内置的ZooKeeper实例。</p>
<p><strong>Example</strong>：<code>bin/solr start -c -z server1:2181,server2:2181</code></p>
<h3 id="-force"><code>-force</code></h3>
<p>Solr不能使用root账户启动，退出的同时会输出错误信息：以root账户运行Solr会导致安全问题。指定此参数可以用root账户启动。</p>
<p><strong>Example</strong>：<code>sudo bin/solr start -force</code></p>
<p>下面两个命令是等价的：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bin/solr start
bin/solr start -h localhost -p 8983 -d server -s solr -m 512m
</code></pre></td></tr></table>
</div>
</div><h2 id="设置jvm参数">设置JVM参数</h2>
<p>跟启动Java程序一样，可以使用<code>-D</code>选项指定属性值。例如，指定自动提交频率为3秒：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bin/solr start -Dsolr.autoSoftCommit.maxTime=3000
</code></pre></td></tr></table>
</div>
</div><h1 id="停止-stop">停止 Stop</h1>
<p><code>stop</code>命令发送一个<code>STOP</code>请求到运行状态节点，这个姿势可以优雅的关闭Solr。此命令会先等待180秒的时间进行优雅的停止，如果还没有停止则强制杀掉进程（kill -9）</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bin/solr stop [options]
bin/solr stop -help
</code></pre></td></tr></table>
</div>
</div><h2 id="停止参数">停止参数</h2>
<h3 id="-p-port-1"><code>-p &lt;port&gt;</code></h3>
<p>停止运行在指定端口的Solr。如果运行多个Solr实例，或者是SolrCloud模式，可以分开指定不同的端口，或者<code>-all</code>来停止。</p>
<p><strong>Example</strong>：<code>bin/solr stop -p 8983</code></p>
<h3 id="-all"><code>-all</code></h3>
<p>停止所有运行中的Solr实例</p>
<p><strong>Example</strong>：<code>bin/solr stop -all</code></p>
<h3 id="-k-key"><code>-k &lt;key&gt;</code></h3>
<p>指定需要停止的Solr的key，默认是solrrocks，可以通过<code>-DSTOP.KEY=solrrocks</code>来指定其他的名字。这个选项不常用</p>
<p><strong>Example</strong>: <code>bin/solr stop -k solrrocks</code></p>
<h1 id="系统信息">系统信息</h1>
<h2 id="版本">版本</h2>
<p><code>version</code>命令可以查看Solr的版本信息：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bin/solr version
</code></pre></td></tr></table>
</div>
</div><h2 id="状态">状态</h2>
<p><code>status</code>用来查看本地运行中的Solr节点的状态信息，以JSON格式输出状态信息。<code>status</code>会读取<code>SOLR_PID_DIR</code>环境变量指定的目录来查找pid文件，默认是<code>bin</code>目录。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bin/solr status
</code></pre></td></tr></table>
</div>
</div><p>输出信息包含每个节点的状态，例如：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">Found 2 Solr nodes:

Solr process 39920 running on port 7574
{
  &#34;solr_home&#34;:&#34;/Applications/Solr/example/cloud/node2/solr/&#34;,
  &#34;version&#34;:&#34;X.Y.0&#34;,
  &#34;startTime&#34;:&#34;2015-02-10T17:19:54.739Z&#34;,
  &#34;uptime&#34;:&#34;1 days, 23 hours, 55 minutes, 48 seconds&#34;,
  &#34;memory&#34;:&#34;77.2 MB (%15.7) of 490.7 MB&#34;,
  &#34;cloud&#34;:{
    &#34;ZooKeeper&#34;:&#34;localhost:9865&#34;,
    &#34;liveNodes&#34;:&#34;2&#34;,
    &#34;collections&#34;:&#34;2&#34;}}

Solr process 39827 running on port 8865
{
  &#34;solr_home&#34;:&#34;/Applications/Solr/example/cloud/node1/solr/&#34;,
  &#34;version&#34;:&#34;X.Y.0&#34;,
  &#34;startTime&#34;:&#34;2015-02-10T17:19:49.057Z&#34;,
  &#34;uptime&#34;:&#34;1 days, 23 hours, 55 minutes, 54 seconds&#34;,
  &#34;memory&#34;:&#34;94.2 MB (%19.2) of 490.7 MB&#34;,
  &#34;cloud&#34;:{
    &#34;ZooKeeper&#34;:&#34;localhost:9865&#34;,
    &#34;liveNodes&#34;:&#34;2&#34;,
    &#34;collections&#34;:&#34;2&#34;}}
</code></pre></td></tr></table>
</div>
</div><h2 id="assert-检查安装正确">Assert 检查安装正确</h2>
<p><code>assert</code>命令可以检查一般的安装问题，检查目录权限，目录是否存在，指定的URL是否可用。此命令会输出错误信息，或者改变exit code（Linux可以使用<code>echo $?</code>查看）。下面是一个例子：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bin/solr assert --exists /opt/bin/solr
</code></pre></td></tr></table>
</div>
</div><p>输出结果如下：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">ERROR: Directory /opt/bin/solr does not exist.
</code></pre></td></tr></table>
</div>
</div><p>使用<code>bin/solr assert -help</code>查看更多<code>assert</code>命令帮助</p>
<h2 id="健康检查">健康检查</h2>
<p><code>healthcheck</code>命令会生成SolrCloud模式下指定collection的JSON格式的健康报告。报告提供关于所有分片的复制的状态信息，包括提交的文档数，当着状态。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bin/solr healthcheck [options]
bin/solr healthcheck -help
</code></pre></td></tr></table>
</div>
</div><h3 id="选项参数">选项参数</h3>
<h4 id="-c-collection"><code>-c &lt;collection&gt;</code></h4>
<p>指定生成报告的collection的名字</p>
<p><strong>Example</strong>：<code>bin/solr healthcheck -c gettingstarted</code></p>
<h4 id="-z-zkhost-1"><code>-z &lt;zkhost&gt;</code></h4>
<p>指定ZooKeeper连接字符串，默认是<code>localhost:9983</code>。如果Solr不是运行在8983端口，就需要指定ZooKeeper连接字符串，一般是solr的端口+1000.</p>
<p><strong>Example</strong>：<code>bin/solr healthcheck -z localhost:2181</code></p>
<p>下面是一个健康检查命令和结果执行：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">$ bin/solr healthcheck -c gettingstarted -z localhost:9865
</code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span><span class="lnt">39
</span><span class="lnt">40
</span><span class="lnt">41
</span><span class="lnt">42
</span><span class="lnt">43
</span><span class="lnt">44
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-json" data-lang="json"><span class="p">{</span>
  <span class="nt">&#34;collection&#34;</span><span class="p">:</span><span class="s2">&#34;gettingstarted&#34;</span><span class="p">,</span>
  <span class="nt">&#34;status&#34;</span><span class="p">:</span><span class="s2">&#34;healthy&#34;</span><span class="p">,</span>
  <span class="nt">&#34;numDocs&#34;</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span>
  <span class="nt">&#34;numShards&#34;</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span>
  <span class="nt">&#34;shards&#34;</span><span class="p">:[</span>
    <span class="p">{</span>
      <span class="nt">&#34;shard&#34;</span><span class="p">:</span><span class="s2">&#34;shard1&#34;</span><span class="p">,</span>
      <span class="nt">&#34;status&#34;</span><span class="p">:</span><span class="s2">&#34;healthy&#34;</span><span class="p">,</span>
      <span class="nt">&#34;replicas&#34;</span><span class="p">:[</span>
        <span class="p">{</span>
          <span class="nt">&#34;name&#34;</span><span class="p">:</span><span class="s2">&#34;core_node1&#34;</span><span class="p">,</span>
          <span class="nt">&#34;url&#34;</span><span class="p">:</span><span class="s2">&#34;http://10.0.1.10:8865/solr/gettingstarted_shard1_replica2/&#34;</span><span class="p">,</span>
          <span class="nt">&#34;numDocs&#34;</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span>
          <span class="nt">&#34;status&#34;</span><span class="p">:</span><span class="s2">&#34;active&#34;</span><span class="p">,</span>
          <span class="nt">&#34;uptime&#34;</span><span class="p">:</span><span class="s2">&#34;2 days, 1 hours, 18 minutes, 48 seconds&#34;</span><span class="p">,</span>
          <span class="nt">&#34;memory&#34;</span><span class="p">:</span><span class="s2">&#34;25.6 MB (%5.2) of 490.7 MB&#34;</span><span class="p">,</span>
          <span class="nt">&#34;leader&#34;</span><span class="p">:</span><span class="kc">true</span><span class="p">},</span>
        <span class="p">{</span>
          <span class="nt">&#34;name&#34;</span><span class="p">:</span><span class="s2">&#34;core_node4&#34;</span><span class="p">,</span>
          <span class="nt">&#34;url&#34;</span><span class="p">:</span><span class="s2">&#34;http://10.0.1.10:7574/solr/gettingstarted_shard1_replica1/&#34;</span><span class="p">,</span>
          <span class="nt">&#34;numDocs&#34;</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span>
          <span class="nt">&#34;status&#34;</span><span class="p">:</span><span class="s2">&#34;active&#34;</span><span class="p">,</span>
          <span class="nt">&#34;uptime&#34;</span><span class="p">:</span><span class="s2">&#34;2 days, 1 hours, 18 minutes, 42 seconds&#34;</span><span class="p">,</span>
          <span class="nt">&#34;memory&#34;</span><span class="p">:</span><span class="s2">&#34;95.3 MB (%19.4) of 490.7 MB&#34;</span><span class="p">}]},</span>
    <span class="p">{</span>
      <span class="nt">&#34;shard&#34;</span><span class="p">:</span><span class="s2">&#34;shard2&#34;</span><span class="p">,</span>
      <span class="nt">&#34;status&#34;</span><span class="p">:</span><span class="s2">&#34;healthy&#34;</span><span class="p">,</span>
      <span class="nt">&#34;replicas&#34;</span><span class="p">:[</span>
        <span class="p">{</span>
          <span class="nt">&#34;name&#34;</span><span class="p">:</span><span class="s2">&#34;core_node2&#34;</span><span class="p">,</span>
          <span class="nt">&#34;url&#34;</span><span class="p">:</span><span class="s2">&#34;http://10.0.1.10:8865/solr/gettingstarted_shard2_replica2/&#34;</span><span class="p">,</span>
          <span class="nt">&#34;numDocs&#34;</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span>
          <span class="nt">&#34;status&#34;</span><span class="p">:</span><span class="s2">&#34;active&#34;</span><span class="p">,</span>
          <span class="nt">&#34;uptime&#34;</span><span class="p">:</span><span class="s2">&#34;2 days, 1 hours, 18 minutes, 48 seconds&#34;</span><span class="p">,</span>
          <span class="nt">&#34;memory&#34;</span><span class="p">:</span><span class="s2">&#34;25.8 MB (%5.3) of 490.7 MB&#34;</span><span class="p">},</span>
        <span class="p">{</span>
          <span class="nt">&#34;name&#34;</span><span class="p">:</span><span class="s2">&#34;core_node3&#34;</span><span class="p">,</span>
          <span class="nt">&#34;url&#34;</span><span class="p">:</span><span class="s2">&#34;http://10.0.1.10:7574/solr/gettingstarted_shard2_replica1/&#34;</span><span class="p">,</span>
          <span class="nt">&#34;numDocs&#34;</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span>
          <span class="nt">&#34;status&#34;</span><span class="p">:</span><span class="s2">&#34;active&#34;</span><span class="p">,</span>
          <span class="nt">&#34;uptime&#34;</span><span class="p">:</span><span class="s2">&#34;2 days, 1 hours, 18 minutes, 42 seconds&#34;</span><span class="p">,</span>
          <span class="nt">&#34;memory&#34;</span><span class="p">:</span><span class="s2">&#34;95.4 MB (%19.4) of 490.7 MB&#34;</span><span class="p">,</span>
          <span class="nt">&#34;leader&#34;</span><span class="p">:</span><span class="kc">true</span><span class="p">}]}]}</span>
</code></pre></td></tr></table>
</div>
</div><h1 id="数据集合collectionscores">数据集合（collections/cores）</h1>
<blockquote>
<p>Collection, Core不知道怎么用中文描述，称作库也不太合适。暂且称为数据集合吧。</p>
</blockquote>
<p><code>bin/solr</code>命令行工具可以帮助创建/删除数据集合（collections/cores），collections是在SolrCloud模式下的概念；cores是非SolrCloud模式下的概念。</p>
<blockquote>
<p>以前的版本没有cloud模式的时候就叫core。</p>
</blockquote>
<h2 id="创建数据集合">创建数据集合</h2>
<p>创建数据集合使用<code>create</code>命令，要求Solr必须是运行状态，具体是创建的collection还是core要根据Solr运行的模式来定。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bin/solr create [options]
bin/solr create -help
</code></pre></td></tr></table>
</div>
</div><h3 id="创建数据集合的选项参数">创建数据集合的选项参数</h3>
<h4 id="-c-name"><code>-c &lt;name&gt;</code></h4>
<p>指定collection/core的名字</p>
<p><strong>Example</strong>：<code>bin/solr create -c mycollection</code></p>
<h4 id="-d-confdir"><code>-d &lt;confdir&gt;</code></h4>
<p>指定使用的配置的目录名字，默认是<code>_default</code>。详情参考<a href="http://lucene.apache.org/solr/guide/7_2/solr-control-script-reference.html#configuration-directories-and-solrcloud">Configuration Directories and SolrCloud</a></p>
<p><strong>Example</strong>：<code>bin/solr create -d _default</code></p>
<h4 id="-n-configname"><code>-n &lt;configName&gt;</code></h4>
<p>指定配置的名字，默认创建同名的collection/core。</p>
<p><strong>Example</strong>：<code>bin/solr create -n basic</code></p>
<h4 id="-p-port-2"><code>-p &lt;port&gt;</code></h4>
<p>指定本地Solr运行的端口来发送创建命令，默认会探测运行中的solr实例的端口。此选择对于一个机器运行多个实例的情况非常有用，可以通过指定端口来指定在不同的实例当中创建collection/core。</p>
<p><strong>Example</strong>：<code>bin/solr create -p 8983</code></p>
<h4 id="-s-shards或-shards"><code>-s &lt;shards&gt;</code>或<code>-shards</code></h4>
<p>指定创建的时候数据集合分成多少个分片（所有分片里面的数据合起来才是完整的一个数据集），默认是1，仅当运行在SolrCloud模式的才用到。</p>
<p><strong>Example</strong>：<code>bin/solr create -s 2</code></p>
<h4 id="-rf-replicas或-replicationfactor"><code>-rf &lt;replicas&gt;</code>或<code>-replicationFactor</code></h4>
<p>指定每个文档的复制数据，默认是1（没有复制）。</p>
<p><strong>Example</strong>：<code>bin/solr create -rf 2</code></p>
<h4 id="-force-1"><code>-force</code></h4>
<p>如果是以root账号运行的此命令，需要此选项来强制运行，否则是运行不了的。</p>
<p><strong>Example</strong>：<code>bin/solr create -c foo -force</code></p>
<h1 id="删除数据集合">删除数据集合</h1>
<p>:TODO</p>

    </div>

    <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">Kevin Jiang</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2018-03-19
        
    </span>
  </p>
  
  <p class="copyright-item">
    <span class="item-title">许可协议</span>
    <span class="item-content"><a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank">CC BY-NC-ND 4.0</a></span>
  </p>
</div>
<div class="post-reward">
  <input type="checkbox" name="reward" id="reward" hidden />
  <label class="reward-button" for="reward">赞赏支持</label>
  <div class="qr-code">
    
    <label class="qr-code-image" for="reward">
        <img class="image" src="/img/wechat_pay_1242x1242.jpg">
        <span>微信打赏</span>
      </label>
    <label class="qr-code-image" for="reward">
        <img class="image" src="/img/alipay_600x600.jpg">
        <span>支付宝打赏</span>
      </label>
  </div>
</div><footer class="post-footer">
      <div class="post-tags">
          <a href="/tags/solr/">Solr</a>
          </div>
      <nav class="post-nav">
        <a class="prev" href="/post/emacs/emacs%E4%B8%8Bpython%E5%BC%80%E5%8F%91%E9%85%8D%E7%BD%AE/">
            <i class="iconfont icon-left"></i>
            <span class="prev-text nav-default">Emacs下Python开发配置</span>
            <span class="prev-text nav-mobile">上一篇</span>
          </a>
        <a class="next" href="/post/searchengine/solr7%E4%B8%AD%E7%9A%84learnin-to-rank%E4%BD%BF%E7%94%A8/">
            <span class="next-text nav-default">Solr7中的learnin to rank使用</span>
            <span class="next-text nav-mobile">下一篇</span>
            <i class="iconfont icon-right"></i>
          </a>
      </nav>
    </footer>
  </article>
        </div>
        

  

  

      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
      <a href="mailto:wenlin1988@126.com" class="iconfont icon-email" title="email"></a>
      <a href="https://www.linkedin.com/in/%E6%96%87%E6%9E%97-%E8%92%8B-0a3204126/" class="iconfont icon-linkedin" title="linkedin"></a>
      <a href="https://github.com/kevindragon" class="iconfont icon-github" title="github"></a>
  <a href="http://kevinjiang.info/index.xml" type="application/rss+xml" class="iconfont icon-rss" title="rss"></a>
</div>

<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://gohugo.io">Hugo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 -
    <a class="theme-link" href="https://github.com/olOwOlo/hugo-theme-even">Even</a>
  </span>

  

  <span class="copyright-year">
    &copy;
    2015 -
    2023<span class="heart"><i class="iconfont icon-heart"></i></span><span>Kevin Jiang</span>
    <a href="https://beian.miit.gov.cn/" target="_blank">湘ICP备2022022745号</a>
  </span>
</div>

    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>



<script type="text/javascript" src="/js/main.min.c99b103c33d1539acf3025e1913697534542c4a5aa5af0ccc20475ed2863603b.js"></script>
  <script type="text/javascript">
    window.MathJax = {
      tex: {
        inlineMath: [['$','$'], ['\\(','\\)']],
        tags: 'ams',
        }
    };
  </script>
  <script type="text/javascript" async src="/lib/mathjax/es5/tex-mml-chtml.js"></script>

<script id="baidu_analytics">
  var _hmt = _hmt || [];
  (function() {
    if (window.location.hostname === 'localhost') return;
    var hm = document.createElement("script"); hm.async = true;
    hm.src = "https://hm.baidu.com/hm.js?b73ff6d4afc4af9e582d8a5dc068bab9";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
</script>






</body>
</html>
